package second.codeTop.package1;

/**
 * @ClassName LC415
 * @description: 字符串相加
 * @author: 荣燊
 * @create: 2022-03-02 14:53
 **/
public class LC415 {
    public static void main(String[] args) {
        String num1 = "9";
        String num2 = "99";
        System.out.println(addStrings(num1, num2));
    }

    public static String addStrings(String num1, String num2) {
        StringBuilder stringBuilder = new StringBuilder();
        int i = num1.length()-1;
        int j = num2.length()-1;
        int flag = 0;
        while (i >= 0 || j >= 0 || flag == 1) {
            if (i >= 0) flag += num1.charAt(i) - '0';
            if (j >= 0) flag += num2.charAt(j) - '0';
            stringBuilder.append(flag % 10);
            flag = flag / 10;
            i--;
            j--;
        }
        return stringBuilder.reverse().toString();
    }
}
